package com.ruoyi.common.utils.clone;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author dam
 * @create 2023/8/30 14:05
 */
public class CloneUtil {

    /**
     * 字典克隆
     *
     * @param originalMap
     * @return
     */
    public static <K, V> HashMap<K, V> hashMapClone(Map<K, V> originalMap) {
        HashMap<K, V> clonedMap = new HashMap<>();
        for (K key : originalMap.keySet()) {
            V value = originalMap.get(key);
            clonedMap.put(key, value);
        }
        return clonedMap;
    }

    /**
     * 集合克隆
     * @param originalList
     * @return
     * @param <T>
     */
    public static <T> ArrayList<T> arrayListClone(List<T> originalList) {
        ArrayList<T> clonedList = new ArrayList<>();
        for (T element : originalList) {
            clonedList.add(element);
        }
        return clonedList;
    }

}
